package com.tyun.common.utils;

import java.util.HashMap;

/**
 * 静态工厂返回
 *
 * @author taocongcong
 * @create 2018-01-24 9:30
 */
public class ResultUtil extends HashMap<String, Object>{

    public ResultUtil() {
        put("code", 0);
    }

    public static ResultUtil ok() {
        return new ResultUtil();
    }

    public static ResultDTO success(String msg) {
        ResultDTO dto = new ResultDTO();
        dto.setCode(BaseConstant.CODE_SUCCESS);
        dto.setMsg(msg);
        return dto;
    }

    public static ResultDTO fail(String msg) {
        ResultDTO dto = new ResultDTO();
        dto.setCode(BaseConstant.CODE_ERROR);
        dto.setMsg(msg);
        return dto;
    }

    public static ResultDTO success(String msg, Object result) {
        return new ResultDTO(BaseConstant.CODE_SUCCESS, msg, result);
    }

    public static ResultDTO fail(String msg, Object result) {
        return new ResultDTO(BaseConstant.CODE_ERROR, msg, result);
    }

    @Override
    public ResultUtil put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
